package com.xzp.yygh.user.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xzp.yygh.common.result.Result;
import com.xzp.yygh.model.user.UserInfo;
import com.xzp.yygh.user.service.UserInfoService;
import com.xzp.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(value = "后台用户审核")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("分页查询用户情况")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page, @PathVariable Long limit, UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParam = new Page<>(page, limit);
        Page<UserInfo> userInfoPage = userInfoService.selectPage(pageParam, userInfoQueryVo);
        return Result.ok(userInfoPage);
    }


    @ApiOperation("锁定用户")
    @GetMapping("lock/{userid}/{status}")
    public Result lock(@PathVariable(name = "userid") Long id,@PathVariable(name="status") Integer status){
        if(status == 0 || status ==1) {
            UserInfo userInfo = userInfoService.getById(id);
            userInfo.setStatus(status);
            userInfoService.updateById(userInfo);
        }
        return Result.ok();
    }


    @ApiOperation("展示用户详情")
    @GetMapping("show/{userid}")
    public Result show(@PathVariable(value = "userid") Long userId){
        Map<String, Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }


    //认证审批
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId, @PathVariable Integer authStatus){
        userInfoService.approval(userId, authStatus);
        return Result.ok();
    }



}
